{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 784. 字母大小写全排列"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "给定一个字符串S，通过将字符串S中的每个字母转变大小写，我们可以获得一个新的字符串。返回所有可能得到的字符串集合。\n",
    "\n",
    "示例:\n",
    "输入: S = \"a1b2\"\n",
    "输出: [\"a1b2\", \"a1B2\", \"A1b2\", \"A1B2\"]\n",
    "\n",
    "输入: S = \"3z4\"\n",
    "输出: [\"3z4\", \"3Z4\"]\n",
    "\n",
    "输入: S = \"12345\"\n",
    "输出: [\"12345\"]\n",
    "\n",
    "来源：力扣（LeetCode）\n",
    "链接：https://leetcode-cn.com/problems/letter-case-permutation"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['a1b2', 'a1B2', 'A1b2', 'A1B2']\n"
     ]
    }
   ],
   "source": [
    "class Solution(object):\n",
    "    def letterCasePermutation(self, S):\n",
    "        \"\"\"\n",
    "        :type S: str\n",
    "        :rtype: List[str]\n",
    "        \"\"\"\n",
    "        if not S:\n",
    "            return ['']\n",
    "        res, tmp = [''],[]\n",
    "        for s in S:\n",
    "            if '0' <= s <= '9':\n",
    "                for item in res:\n",
    "                    tmp.append(item + s)\n",
    "            else:\n",
    "                for item in res:\n",
    "                    tmp.append(item + s.lower())\n",
    "                    tmp.append(item + s.upper())\n",
    "            res, tmp = tmp, []\n",
    "        return res\n",
    "    \n",
    "if __name__ == \"__main__\":\n",
    "    Sol = Solution()\n",
    "    end = Sol.letterCasePermutation(\"a1b2\")\n",
    "    print(end)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.5"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
